package com.mark.web.bill.service.impl;

import com.mark.common.Constant;
import com.mark.web.bill.entity.po.GoodsImg;
import com.mark.web.bill.exception.BillException;
import com.mark.web.bill.mapper.GoodsImgMapper;
import com.mark.web.bill.service.IGoodsImgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Description: 加工零件图片资源的业务实现
 * @Author: Mark
 * @CreateDate: 2019/2/11 23:38
 * @Version: 2.0
 * @Copyright : 豆浆油条个人非正式工作室
 */
@Service
public class GoodsImgServiceImpl implements IGoodsImgService {
    @Autowired
    private GoodsImgMapper goodsImgMapper;

    @Override
    public void add(String url, Integer goodsId) {
        GoodsImg goodsImg = new GoodsImg();
        goodsImg.setGoodsId(goodsId);
        goodsImg.setImgAddr(url);
        goodsImg.setPriority(0);
        goodsImg.setEnableStatus(1);
        int effectNum = goodsImgMapper.insert(goodsImg);
        if(effectNum != Constant.SUCCESS){
            throw new BillException("保存加工零件图片数据失败！");
        }
    }

    //region 更新加工零件图片
    @Override
    public void update(String url, Integer goodsId) {
        GoodsImg goodsImg = goodsImgMapper.selectByFkGoodsId(goodsId);
        goodsImg.setImgAddr(url);
        int update = goodsImgMapper.updateByPrimaryKeySelective(goodsImg);
        if(update != Constant.SUCCESS){
            throw new BillException("更新加工零件图片失败！");
        }
    }
    //endregion


}
